package com.liveneo.adapter.mobile.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.liveneo.adapter.base.entity.PrpmCaseInfo;
import com.liveneo.adapter.base.entity.PrpmVideo;
import com.liveneo.adapter.base.mapper.PrpmVideoMapper;
import com.liveneo.adapter.mobile.model.dto.PrpmReplayDto;
import com.liveneo.adapter.mobile.model.dto.PrpmVideoDto;
import com.liveneo.adapter.mobile.service.VideoService;

@Service
public class VideoServiceImpl implements VideoService {
    @Autowired
    private PrpmVideoMapper prpmVideoMapper;

    @Override
    public List<PrpmVideo> getVideoList(String caseUuid) throws Exception {
        return prpmVideoMapper.selectByUuid(caseUuid);
    }

    @Override
    public List<PrpmVideo> selectByCaseNo(String caseNo) throws Exception {
        return prpmVideoMapper.selectByCaseNo(caseNo);
    }

    @Override
    public List<PrpmVideo> selectByBean(int currentPage, int pagesize, PrpmVideoDto prpmVideoDto) {
        PageHelper.startPage(currentPage, pagesize);
        return prpmVideoMapper.selectByBean(prpmVideoDto);
    }

    @Override
    public void save(PrpmVideo video) {
        prpmVideoMapper.insert(video);
    }

    @Override
    public PrpmVideo selectByFlowNo(String flowNo) {
        return prpmVideoMapper.selectByFlowNo(flowNo);
    }

    @Override
    public void updateVideo(PrpmVideo video) {
        prpmVideoMapper.updateByPrimaryKey(video);
    }

    @Override
    public List<PrpmVideo> selectToBeUpload() throws Exception {
        return prpmVideoMapper.selectToBeUpload();
    }

    @Override
    public List<PrpmVideo> selectToBeUploadByCaseUuid(String caseUuid) throws Exception {
        return prpmVideoMapper.selectToBeUploadByCaseuuid(caseUuid);
    }

    @Override
    public List<PrpmVideo> selectToBeUploadByCaseNo(String caseNo) throws Exception {
        return prpmVideoMapper.selectToBeUploadByCaseno(caseNo);
    }

    @Override
    public List<PrpmVideo> selectByCaseUuidAndVideoType(String caseUuid) throws Exception {
        return prpmVideoMapper.selectByCaseUuidAndVideoType(caseUuid);
    }

    @Override
    public void saveList(List<PrpmVideo> videos) {
        prpmVideoMapper.insertMoreRows(videos);
    }

    @Override
    public List<PrpmVideo> selectByCaseNoVideoTypeAndUpload(String caseNo) throws Exception {
        return prpmVideoMapper.selectByCaseNoVideoTypeAndUpload(caseNo);
    }

    @Override
    public List<PrpmVideo> selectByUserCode(String userCode) throws Exception {
        return prpmVideoMapper.selectByUserCode(userCode);
    }

    @Override
    public List<PrpmReplayDto> selectReplayList(int currentPage, int pagesize, PrpmReplayDto replayDto) {
        PageHelper.startPage(currentPage, pagesize);
        return prpmVideoMapper.selectReplayList(replayDto);
    }

    @Override
    public void saveStartVideo(PrpmVideo video, PrpmCaseInfo prpmcaseinfo, String flowNo) throws Exception {
        // prpmcaseinfo.setCaseStatus(Constant.CASE_CONNECTSUCCESS);
        // //更新案件状态为连线完成
        // caseInfoService.updateByPrimaryKey(prpmcaseinfo);
        // 增加视频记录
        prpmVideoMapper.insert(video);
    }

    @Override
    public List<PrpmVideo> selectVideoFail(int currentPage, int pagesize, PrpmVideo prpmVideo) {
        PageHelper.startPage(currentPage, pagesize);
        return prpmVideoMapper.selectVideoFail(prpmVideo);
    }

    @Override
    public List<PrpmVideo> selectBycaseNoAndUserCode(String caseNo) throws Exception {
        return prpmVideoMapper.selectByCaseNoAndUseCode(caseNo);
    }

    @SuppressWarnings({ "rawtypes", "unchecked" })
    @Override
    public void updateUserCodeByCaseNo(String caseNo, String userCode) {
        Map params = new HashMap();
        params.put("caseNo", caseNo);
        params.put("userCode", userCode);
        prpmVideoMapper.updateUserCodeByCaseNo(params);
    }

    @Override
    public String getRecentAgtID(String caseUuid) {
        return prpmVideoMapper.selectRecentAgtID(caseUuid);
    }

    @Override
    public PrpmVideo selectByOssUuidAndBreakPointFlag(String ossUuid) {
        return prpmVideoMapper.selectByOssUuidAndBreakPointFlag(ossUuid);
    }
}
